package com.atty.dms.controller;

import com.atty.dms.common.convention.result.Result;
import com.atty.dms.common.convention.result.Results;
import com.atty.dms.dto.req.DormitoryCreateReqDTO;
import com.atty.dms.dto.req.DormitoryUpdateReqDTO;
import com.atty.dms.dto.resp.DormitoryRespDTO;
import com.atty.dms.service.DormitoryService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName:DomitoryController
 * Package:com.atty.dms.controller
 * Description:
 *
 * @Author:tony
 * @Create :2025/4/15 9:33
 * @Version :1.0
 */
@RestController
@RequiredArgsConstructor
public class DormitoryController {

    private final DormitoryService dormitoryService;


    /**
     * 根据宿舍id获取宿舍信息
     */
    @GetMapping("/api/dms/admin/dormitory/id/{dormitoryId}")
    public Result<DormitoryRespDTO> getDormitoryById(@PathVariable("dormitoryId") String dormitoryId){
        return Results.success(dormitoryService.getDormitoryById(dormitoryId));
    }


    /**
     * 根据宿舍编号获取宿舍信息
     */
    @GetMapping("/api/dms/admin/dormitory/number/{dormitoryNumber}")
    public Result<DormitoryRespDTO> getDormitoryByDormitoryNumber(@PathVariable("dormitoryNumber") String dormitoryNumber){
        return Results.success(dormitoryService.getDormitoryByDormitoryNumber(dormitoryNumber));
    }

    /**
     * 创建新宿舍
     */
    @PostMapping("/api/dms/admin/dormitory")
    public Result<Void> createDormitory(@RequestBody DormitoryCreateReqDTO requestParam) {
        dormitoryService.createDormitory(requestParam);
        return Results.success();
    }

    /**
     * 修改宿舍信息
     */
    @PutMapping("/api/dms/admin/dormitory")
    public Result<Void> updateDormitory(@RequestBody DormitoryUpdateReqDTO requestParam) {
        dormitoryService.updateDormitory(requestParam);
        return Results.success();
    }

    /**
     * 根据宿舍id删除宿舍信息
     */
    @DeleteMapping("/api/dms/admin/dormitory/{dormitoryId}")
    public Result<Void> deleteDormitoryById(@PathVariable("dormitoryId") String dormitoryId) {
        dormitoryService.deleteDormitoryById(dormitoryId);
        return Results.success();
    }

    /**
     * 获取所有宿舍信息
     */
    @GetMapping("/api/dms/admin/dormitory/page")
    public Result<Page<DormitoryRespDTO>> getAllDormitoriesByPage(
            @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10") int sizeNum){
        return Results.success(dormitoryService.getAllDormitoriesByPage(pageNum, sizeNum));
    }
}
